﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ChuanYe.CountyFireManagement.Api.Models;
using ChuanYe.CountyFireManagement.EF.MySQL.Models;
using ChuanYe.CountyFireManagement.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace ChuanYe.CountyFireManagement.Api.Controllers
{
    /// <summary>
    /// 火灾终报
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FireFinalReportController : ControllerBase
    {
        /// <summary>
        ///  增加
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase Add(FireFinalReportRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            string ip = HttpContext.GetClientIp();
            Firefinalreport info = new Firefinalreport()
            {
                AlarmTypeId = obj.AlarmTypeId,
                ArmyPeopleSum = obj.ArmyPeopleSum,
                ArmyRankSum = obj.ArmyRankSum,
                BurnedArea = obj.BurnedArea,
                BurnedAreaUnit = obj.BurnedAreaUnit,
                BurnedTreeAge = obj.BurnedTreeAge,
                BurnedTreeDieSum = obj.BurnedTreeDieSum,
                BurnedTreeSum = obj.BurnedTreeSum,
                BurnedTreeTypeSum = obj.BurnedTreeTypeSum,
                Casualties = obj.Casualties,
                CauseId = obj.CauseId,
                FinalReportContent = obj.FinalReportContent,
                FinalReportId = obj.FinalReportId,
                FireId = obj.FireId,
                ForestBurnedArea = obj.ForestBurnedArea,
                ForestBurnedAreaUnit = obj.ForestBurnedAreaUnit,
                Humidity = obj.Humidity,
                Ip = ip,
                IsSupplementary = obj.IsSupplementary,
                Leader = obj.Leader,
                OtherSituation = obj.OtherSituation,
                ProfessionalPeopleSum = obj.ProfessionalPeopleSum,
                ProfessionalRankSum = obj.ProfessionalRankSum,
                PutOutTime = obj.PutOutTime,
                ReportTime = obj.ReportTime,
                StationPeopleSum = obj.StationPeopleSum,
                StationRankSum = obj.StationRankSum,
                Temperature = obj.Temperature,
                TownPeopleSum = obj.TownPeopleSum,
                TownRankSum = obj.TownRankSum,
                TransDatetime = obj.TransDatetime.HasValue ? obj.TransDatetime.Value : DateTime.Now,
                UserId = obj.UserId,
                Weather = obj.Weather,
                WindDirection = obj.WindDirection,
                WindPower = obj.WindPower,
                CaseFiles=obj.CaseFiles,
                IdentifyFiles=obj.IdentifyFiles
            };
            try
            {
                var data = BLL.FireFinalReportBLL.Instance.Add(info);
                if (data.FirstParam != null)
                {
                    ControllerHelper.SendMessage(data.FirstParam);
                    var allExpireFreInfo = BLL.FireExpireBLL.Instance.GetUnExpire();
                    MqttHub.fireexpires = allExpireFreInfo;
                }
                result.Status = data.Status;
                result.Message = data.Message;
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/FireFinalReport/Add Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }
    }
}